<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *客户列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'网络客户数量'),
);
if($_SESSION['juese_id']>6 && $_SESSION['juese_id']<15){
	exi('您无权访问！','error');
}
//客户列表
if($_RQ['op']=='list'){
	$params=array('from_type'=>2,'worker6id'=>$_SESSION['workerid'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['from2_type']){
		$types=array($_RQ['from2_type']=>$this->member_from2_type[$_RQ['from2_type']]);
	}else{
		$types=$this->member_from2_type;
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$between=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$return['params']=array('createtime'=>'');
	if($types){
		$statusshangmen=$this->model('model')->get_memberstatus('shangmen');
		$shmennumparams=$shmennum2params=$tingnumparams=$xuenumparams=$baonumparams=$params;
		$shmennum2params['status >']=0;
		if(!$between){
			$shmennumparams['zhun_time >']=0;
			$shmennum2params['zhun_time >']=0;
			$tingnumparams['ti5_time >']=0;
			$xuenumparams['ti7_time >']=0;
			$baonumparams['buy_time >']=0;
		}else{
			$shmennumparams['zhun_time between']=$between;
			$shmennum2params['zhun_time between']=$between;
			$tingnumparams['ti5_time between']=$between;
			$xuenumparams['ti7_time between']=$between;
			$baonumparams['buy_time between']=$between;
		}
		$list=array();
		$list[]=array('id'=>'all','title'=>'全部统计');
		foreach($types as $k=>$v){
			$list[]=array('id'=>$k,'title'=>$v);
		}
		foreach($list as &$item){
			unset($params['status']);
			unset($params['from2_type']);
			if(!$item['id'] || $item['id']!='all'){
				$params['from2_type']=$item['id'];
				$shmennumparams['from2_type']=$item['id'];
				$shmennum2params['from2_type']=$item['id'];
				$tingnumparams['from2_type']=$item['id'];
				$xuenumparams['from2_type']=$item['id'];
				$baonumparams['from2_type']=$item['id'];
				
			}
			$item['allnum']=pdo_count('jy_yxw_member',$params);
			$params['status']=-1;
			$item['wunum']=pdo_count('jy_yxw_member',$params);
			$params['status']=array(101,102,103);
			$item['tuinum']=pdo_count('jy_yxw_member',$params);
			$item['shmennum']=pdo_count('jy_yxw_member',$shmennumparams);
			$item['shmennum2']=pdo_count('jy_yxw_member',$shmennum2params);
			$item['tingnum']=pdo_count('jy_yxw_member',$tingnumparams);
			$item['xuenum']=pdo_count('jy_yxw_member',$xuenumparams);
			$item['baonum']=pdo_count('jy_yxw_member',$baonumparams);
		}
	}
	$return['list']=$list;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export',
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：
		</br>1、这里显示本销售员的渠道数据！
		','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'类型','type'=>'string'),
			array('name'=>'allnum','title'=>'客户数量','type'=>'string'),
			array('name'=>'wunum','title'=>'无效客户数量','type'=>'string'),
			array('name'=>'tingnum','title'=>'体验数量','type'=>'string'),
			array('name'=>'xuenum','title'=>'体用数量','type'=>'string'),
			array('name'=>'baonum','title'=>'成交数量','type'=>'string'),
			array('name'=>'tuinum','title'=>'退费数量','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'from2_type','width'=>15,'title'=>'线下来源','type'=>'radio','options'=>'from2_type'),
			array('name'=>'createtime','width'=>15,'title'=>'时间段','type'=>'time_range')
		),
	);
	$return['from2_type']=$this->member_from2_type;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	//客户列表
	$params=array('from_type'=>2,'worker6id'=>$_SESSION['workerid'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['from2_type']){
		$types=array($_RQ['from2_type']=>$this->member_from2_type[$_RQ['from2_type']]);
	}else{
		$types=$this->member_from2_type;
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$between=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$return['params']=array('createtime'=>'');
	if($types){
		$statusshangmen=$this->model('model')->get_memberstatus('shangmen');
		$shmennumparams=$shmennum2params=$tingnumparams=$xuenumparams=$baonumparams=$params;
		$shmennum2params['status >']=0;
		if(!$between){
			$shmennumparams['zhun_time >']=0;
			$shmennum2params['zhun_time >']=0;
			$tingnumparams['ti5_time >']=0;
			$xuenumparams['ti7_time >']=0;
			$baonumparams['buy_time >']=0;
		}else{
			$shmennumparams['zhun_time between']=$between;
			$shmennum2params['zhun_time between']=$between;
			$tingnumparams['ti5_time between']=$between;
			$xuenumparams['ti7_time between']=$between;
			$baonumparams['buy_time between']=$between;
		}
		$list=array();
		$list[]=array('id'=>'all','title'=>'全部统计');
		foreach($types as $k=>$v){
			$list[]=array('id'=>$k,'title'=>$v);
		}
		foreach($list as &$item){
			unset($params['status']);
			unset($params['from2_type']);
			if(!$item['id'] || $item['id']!='all'){
				$params['from2_type']=$item['id'];
				$shmennumparams['from2_type']=$item['id'];
				$shmennum2params['from2_type']=$item['id'];
				$tingnumparams['from2_type']=$item['id'];
				$xuenumparams['from2_type']=$item['id'];
				$baonumparams['from2_type']=$item['id'];
				
			}
			$item['allnum']=pdo_count('jy_yxw_member',$params);
			$params['status']=-1;
			$item['wunum']=pdo_count('jy_yxw_member',$params);
			$item['shmennum']=pdo_count('jy_yxw_member',$shmennumparams);
			$item['shmennum2']=pdo_count('jy_yxw_member',$shmennum2params);
			$item['tingnum']=pdo_count('jy_yxw_member',$tingnumparams);
			$item['xuenum']=pdo_count('jy_yxw_member',$xuenumparams);
			$item['baonum']=pdo_count('jy_yxw_member',$baonumparams);
		}
	}
	$header=array(
		'title'=>'类型',
		'allnum'=>'客户数量',
		'wunum'=>'无效客户数量',
		'shmennum'=>'意向数量',
		'shmennum2'=>'有效意向数量',
		'tingnum'=>'体验数量',
		'xuenum'=>'体用数量',
		'baonum'=>'成交数量',
	);
	model('core/tools')->export2excel($header,$list,'渠道客户数量');
}